function parseData(){
	$.ajax({
		"url":"/get_class_admin/",
		"error":errorAjax,
		"beforeSend":start_load_pic,
		"complete":stop_load_pic,
		"dataType":"jsonp",
		"async":false,
		"success":function(data){
			if(!data.status){
				showErrorInfo(data.content)
				return false;
			}
			data=data.content
			var select=document.getElementById("class_number")
			for(var i=0;i<data.length;i++){
				var option=document.createElement("option")
				option.setAttribute("value",data[i].sid)
				option.textContent=data[i].name
				select.appendChild(option)
			}
		}
	})
	var data=getQ().data
	data=JSON.parse(data)
	console.log(data)
	$("#class_number").find("option[value="+"'"+data.class_number+"'"+"]").attr("selected",true)
	$("#name").val(data.name);
	$("#inventory_id").attr("s",data.inventory_id)
	var l=JSON.parse(data.inventory_id).length
	$("#inventory_id").attr("value","已选中 "+ l+ " 道题")
	$("#value").val(data.value)
	
}
function go(){
	var data={}
	data.class_number=$("#class_number").val()
	data.name=$("#name").val()
	data.inventory_id=$("#inventory_id").attr("s")
	if(/^ *$/.test(data.name)){
		showErrorInfo("习题作业名称不能为空！")
		return false
	}
	if(data.class_number===null){
		showErrorInfo("请选择班级！")
		return false;
	}
	if(JSON.parse(data.inventory_id).length===0){
		showErrorInfo("请选择题目！")
		return false;
	}
	if(getQ().type==="PUT"){
		data.id=JSON.parse(getQ().data).id
	}
	data=JSON.stringify(data)
	$.ajax({
		"url":"/ti/",
		"error":errorAjax,
		"beforeSend":start_load_pic,
		"complete":stop_load_pic,
		"data":{"data":data},
		"type":getQ().type,
		"success":function(data){
			data=JSON.parse(data)
			if(!data.status){
				showErrorInfo(data.content)
				return false;
			}
			alert("操作成功!")
			window.opener.location.reload()
			window.close()
		}
	})
}
function view(){
	var ti=$("#inventory_id").attr("s")
	var _ti=JSON.parse(ti)
	if(_ti.length===0){
		showErrorInfo("当前尚未选择题目，不能生成预览！")
		return false;
	}
	var name=document.getElementById("name").value;
	window.open ("ti.html?s="+ti+"&name="+name, "_blank", "height=800, width=1300, top=160, left=200, toolbar=no, menubar=no, scrollbars=yes, resizable=no, location=no, status=no");
}
document.getElementById("inventory_id").onclick=function(){
	var s=this.getAttribute("s")
	window.open ("search_inventory.html?inventory_id="+s, "_blank", "height=800, width=1300, top=160, left=200, toolbar=no, menubar=no, scrollbars=yes, resizable=no, location=no, status=no");
}
document.getElementById("confirm").onclick=function(){
	go()
}
document.getElementById("view").onclick=function(){
	view()
}
parseData()
